package com.csu.mall.ware.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csu.mall.common.utils.PageUtils;
import com.csu.mall.common.utils.Query;
import com.csu.mall.ware.dao.WareSkuDao;
import com.csu.mall.ware.entity.WareInfoEntity;
import com.csu.mall.ware.entity.WareSkuEntity;
import com.csu.mall.ware.service.WareSkuService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;


@Service("wareSkuService")
public class WareSkuServiceImpl extends ServiceImpl<WareSkuDao, WareSkuEntity> implements WareSkuService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        QueryWrapper<WareSkuEntity> wrapper = new QueryWrapper<>();
        String wareIdStr = (String) params.get("wareId");
        if(!StringUtils.isEmpty(wareIdStr)){
            Long wareId = Long.parseLong(wareIdStr);
            if(wareId > 0){
                wrapper.eq("ware_id", wareId);
            }
        }
        String skuIdStr = (String) params.get("skuId");
        if(!StringUtils.isEmpty(skuIdStr)){
            Long skuId = Long.parseLong(skuIdStr);
            if(skuId > 0){
                wrapper.eq("sku_id", skuId);
            }
        }
        IPage<WareSkuEntity> page = this.page(
                new Query<WareSkuEntity>().getPage(params),
                wrapper
        );

        return new PageUtils(page);
    }

}